/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.padrao.view;

import br.com.webhomesites.padrao.model.ProdutoModel;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;
import java.util.List;
import javax.swing.JComboBox;

/**
 *
 * @author Webhome
 */
public class BuscarProdutoView extends javax.swing.JDialog {

    /**
     * Creates new form BuscarProdutoView
     */
    public BuscarProdutoView(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelBuscaProduto = new javax.swing.JPanel();
        comboCodigo = new javax.swing.JComboBox();
        comboDescricao = new javax.swing.JComboBox();
        comboSerie = new javax.swing.JComboBox();
        labelCodigo = new javax.swing.JLabel();
        labelDescricao = new javax.swing.JLabel();
        labelSerie = new javax.swing.JLabel();
        btnBuscar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        painelBuscaProduto.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar Produto"));

        comboCodigo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar" }));

        comboDescricao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar" }));
        comboDescricao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboDescricaoActionPerformed(evt);
            }
        });

        comboSerie.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar" }));
        comboSerie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboSerieActionPerformed(evt);
            }
        });

        labelCodigo.setText("Código");

        labelDescricao.setText("Descrição");

        labelSerie.setText("Série");

        javax.swing.GroupLayout painelBuscaProdutoLayout = new javax.swing.GroupLayout(painelBuscaProduto);
        painelBuscaProduto.setLayout(painelBuscaProdutoLayout);
        painelBuscaProdutoLayout.setHorizontalGroup(
            painelBuscaProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelBuscaProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelBuscaProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comboDescricao, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(painelBuscaProdutoLayout.createSequentialGroup()
                        .addGroup(painelBuscaProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelCodigo)
                            .addComponent(labelDescricao)
                            .addComponent(labelSerie)
                            .addComponent(comboCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(comboSerie, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        painelBuscaProdutoLayout.setVerticalGroup(
            painelBuscaProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelBuscaProdutoLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(labelCodigo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelDescricao)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelSerie)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        btnBuscar.setText("Buscar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 386, Short.MAX_VALUE)
                        .addComponent(btnBuscar))
                    .addComponent(painelBuscaProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(painelBuscaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnBuscar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void comboSerieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSerieActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboSerieActionPerformed

    private void comboDescricaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboDescricaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboDescricaoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BuscarProdutoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BuscarProdutoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BuscarProdutoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BuscarProdutoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                BuscarProdutoView dialog = new BuscarProdutoView(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JComboBox comboCodigo;
    private javax.swing.JComboBox comboDescricao;
    private javax.swing.JComboBox comboSerie;
    private javax.swing.JLabel labelCodigo;
    private javax.swing.JLabel labelDescricao;
    private javax.swing.JLabel labelSerie;
    private javax.swing.JPanel painelBuscaProduto;
    // End of variables declaration//GEN-END:variables

    public void packAndShow() {
        this.pack();
        this.setVisible(true);
    }

    public Long getComboCodigo() {
        return Long.parseLong(comboCodigo.getSelectedItem().toString());
    }

    public void setComboCodigo(String comboCodigo) {
        this.comboCodigo.setSelectedItem(comboCodigo);
    }

    public String getComboDescricao() {
        return comboDescricao.getSelectedItem().toString();
    }

    public void setComboDescricao(String comboDescricao) {
        this.comboDescricao.setSelectedItem(comboDescricao);
    }

    public String getComboSerie() {
        return comboSerie.getSelectedItem().toString();
    }

    public void setComboSerie(String comboSerie) {
        this.comboSerie.setSelectedItem(comboSerie);
    }

    public void setListaCodigo(List<ProdutoModel> listaProdutoModel) {
        comboCodigo.removeAllItems();
        for (int i = 0; i < listaProdutoModel.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboCodigo.addItem(listaProdutoModel.get(i).getId()); // Adiciono os dados.  
        }

    }

    public void setListaDescricao(List<ProdutoModel> listaProdutoModel) {
        comboDescricao.removeAllItems();
        for (int i = 0; i < listaProdutoModel.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboDescricao.addItem(listaProdutoModel.get(i).getDescricao()); // Adiciono os dados.  
        }
    }

    public void setListaSerie(List<ProdutoModel> listaProdutoModel) {
        comboSerie.removeAllItems();

        for (int i = 0; i < listaProdutoModel.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            if (!listaProdutoModel.get(i).getSerie().contains("*")) {
                this.comboSerie.addItem(listaProdutoModel.get(i).getSerie()); // Adiciono os dados.  
            }
        }
    }

    public void setCodigoFocusListener(FocusListener listener) {
        comboCodigo.addFocusListener(listener);
    }

    public void setDescricaoFocusListener(FocusListener listener) {
        comboDescricao.addFocusListener(listener);
    }

    public void setSerieFocusListener(FocusListener listener) {
        comboSerie.addFocusListener(listener);
    }

    public void setBtnBuscarActionListener(ActionListener listener) {
        btnBuscar.addActionListener(listener);
    }

    public JComboBox getComboCodigoJCombo() {
        return comboCodigo;
    }

    public JComboBox getComboDescricaoJCombo() {
        return comboDescricao;
    }

    public JComboBox getComboSerieJCombo() {
        return comboSerie;
    }

    public void comboCodigoRemoveAllItens() {
        comboCodigo.removeAllItems();
    }

    public void comboDescricaoRemoveAllItens() {
        comboDescricao.removeAllItems();
    }

    public void comboSerieRemoveAllItens() {
        comboSerie.removeAllItems();
    }
}
